using HKB.Common;
using System;
using System.Data;
namespace HKB.Web.DataHelper
{
	public class CM_ServiceSortBll
	{
		private Conn conn = null;
		public CM_ServiceSortBll()
		{
			this.conn = new Conn();
		}
		public CM_ServiceSortBll(Conn _conn)
		{
			this.conn = _conn;
		}
		public DataTable GetCMServicesortAll()
		{
			string sql = "select * from CM_ServiceSort  where ParentID in (select ServiceSortID from CM_ServiceSort  where ParentID=0 ) ";
			return this.conn.GetDataTable(sql);
		}
		public DataTable GetCMServiceChildSortByID(int ParentID)
		{
			string commandText = "select * from CM_ServiceSort where ParentID=@ParentID";
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@ParentID", DbType.Int32, ParentID);
			return this.conn.GetDataTable(commandText, new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public DataTable GetCMserChildSortFirst()
		{
			string sql = "select * from CM_ServiceSort where ParentID=0";
			return this.conn.GetDataTable(sql);
		}
		public DataTable GetCMSerChildSortSecondByClassID(int ClassID)
		{
			string commandText = "select * from CM_ServiceSort where ParentID=@ClassID";
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@ClassID", DbType.Int32, ClassID);
			return this.conn.GetDataTable(commandText, new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public DataTable GetCMSerChildSortThreeByClassID(int ClassID)
		{
			string commandText = "select * from CM_ServiceSort where ServiceSortID=@ServiceSortID";
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@ServiceSortID", DbType.Int32, ClassID);
			return this.conn.GetDataTable(commandText, new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public bool UpdateClass(int ServiceSortID, int ParentID, string ClassName)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@ServiceSortID", DbType.Int32, ServiceSortID),
				this.conn.CreateParameter("@ParentID", DbType.Int32, ParentID),
				this.conn.CreateParameter("@ClassName", DbType.String, ClassName)
			};
			return this.conn.Execute(" update CM_ServiceSort set ClassName=@ClassName,ParentID=@ParentID where ServiceSortID=@ServiceSortID", parameters) > 0;
		}
		public bool AddClass(int ParentID, string ClassName)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@ParentID", DbType.Int32, ParentID),
				this.conn.CreateParameter("@ClassName", DbType.String, ClassName)
			};
			return this.conn.Execute("  insert into CM_ServiceSort (ClassName,ParentID) values(@ClassName,@ParentID) ", parameters) > 0;
		}
	}
}
